#include "common.hpp"
//写文件只需要向管道文件的传入数据
int main()
{
    //打开管道文件
    int fd = open(Path, O_WRONLY);
    if(fd == -1)
    {
        cout << "use write open pipe file fail" << endl;
        cerr << "errno : " << errno << ", strerror : " << strerror(errno) << endl;
        exit(-1);
    }
    cout << "write open pipe file success" << endl;
    
    //开始写入
    string buffer;
    while(true)
    {
        
        cout << "write message: ";
        getline(cin, buffer);

        if(buffer == "quit")
            break;

        ssize_t n = write(fd, buffer.c_str(), buffer.size());

        if(n == -1)
        {
            cout << "write pipe file fail" << endl;
            cerr << "errno : " << errno << ", strerror : " << strerror(errno) << endl;
            exit(-1);
        }

    }
    close(fd);
    return 0;
}